/**
  ******************************************************************************
  * @file    acad_cfg.h
  * @author  Sherlock
  * @version V0.1
  * @date    08/7/2024
  * @brief   Initial all Periphs
  ******************************************************************************
  * @copy
  *
  * <h2><center>&copy; COPYRIGHT 2010 Feirui</center></h2>
  */ 

#ifndef  __ACAD_CFG_H__
#define  __ACAD_CFG_H__

#ifdef __cplusplus
 extern "C" {
#endif


/**
  * @brief  INCLUDE FILES.
  */
#include "Common_Types.h"


/**
  * @brief GLOBALS RAM definition
  */
#ifdef   ACAD_CFG_GLOBALS
#define  ACAD_CFG_EXT
#else
#define  ACAD_CFG_EXT  extern
#endif


/****************************************/
/* GPIO Initial Group */
/****************************************/
#define ACADCPortCfgNumber     16
ACAD_CFG_EXT const GPIOPortCfg_TypeDef ACADCPortCfgTbl[ACADCPortCfgNumber];



/****************************************/
/* ADC Data Order */
/****************************************/
#define ADCDMAChannelOrd_GensU             0
#define ADCDMAChannelOrd_DroopA            1
#define ADCDMAChannelOrd_GensV             2
#define ADCDMAChannelOrd_DroopB            3
#define ADCDMAChannelOrd_GensW             4
#define ADCDMAChannelOrd_DroopC            5
#define ADCDMAChannelOrd_LoadU             6
#define ADCDMAChannelOrd_GensN             7
#define ADCDMAChannelOrd_LoadV             8
#define ADCDMAChannelOrd_BuildVoltAFT      9
#define ADCDMAChannelOrd_LoadW             10
#define ADCDMAChannelOrd_BuildVoltBEF      11
#define ADCDMAChannelOrd_GenEXCV           12
#define ADCDMAChannelOrd_LoadEXCV          13
#define ADCDMAChannelOrd_GenEXCI           14
#define ADCDMAChannelOrd_LoadEXCI          15
#define ADCDMA_ChannelNum                  16

#define ADCSampleTimesTOTNum                1600 //每个通道总共1600个数据
#define ADC2bBufferNum                      (ADCSampleTimesTOTNum*ADCDMA_ChannelNum) //总共25600个采样数据
#define ADC4bBufferNum                      (ADC2bBufferNum/2) //32位下，共有128000个DMA数据

#define ADCBufferAreaNum                    16 //16个DMA缓存区
#define ADCDMATotalNum                      (ADC4bBufferNum/ADCBufferAreaNum)  /* Total DMA transfer Data Number, DMA每次工作需要搬运800个DMA数据（32位） */
#define ADCDataTotalNum                     (ADC2bBufferNum/ADCBufferAreaNum)  //每个缓冲区的16位数据总量，1600个
#define ADCSampleNumber                     (ADCDataTotalNum/ADCDMA_ChannelNum) //每个缓存块、每个通道的采样点100个
#define ADCBufferArea2Num                   2 //缓冲区2长度：2，用于计算过零点

/* ADC Buffer Adr list */
ACAD_CFG_EXT const uint32_t ACBufferArea1Address[ADCBufferAreaNum+1];

/* Zero pass data buffer */
#define ADCPassZeroVoltGenU             0
#define ADCPassZeroVoltGenV             1
#define ADCPassZeroVoltGenW             2
// #define ADCZeroPassCurrU             3
// #define ADCZeroPassCurrV             4
// #define ADCZeroPassCurrW             5
#define ADCPassZeroVoltLoadU            3
#define ADCPassZeroVoltLoadV            4
#define ADCPassZeroVoltLoadW            5
#define ADCBuildVoltBEF              6
#define ADCPassZero_ChannelNum      7
#define ADCPassZero_TOTNum   (ADCBufferArea2Num*ADCSampleNumber*ADCPassZero_ChannelNum)   //2000
ACAD_CFG_EXT __IO int16_t ADCPassZeroLowPassTab[ADCPassZero_TOTNum];  //three phases

//ADC数据缓冲
typedef union
{
	 int16_t              ADC2bArray[ADC2bBufferNum];
	uint32_t              ADC4bArray[ADC4bBufferNum];
} ADCMSBuffer_TypeDef;
ACAD_CFG_EXT __IO ADCMSBuffer_TypeDef ADCConvertedValueTab1;

//指示当前缓冲区位置
ACAD_CFG_EXT __IO uint8_t ACMeasureBufferAreaNum;


/****************************************/
/* ADC Initial Group */
/****************************************/
#define ADC_RegularNumber              ADCDMA_ChannelNum/2
ACAD_CFG_EXT const ADCRegularCfg_TypeDef ADC1RegularTbl[ADC_RegularNumber];
ACAD_CFG_EXT const ADCRegularCfg_TypeDef ADC2RegularTbl[ADC_RegularNumber];


#ifdef __cplusplus
}
#endif


#endif   /*   ACAD_CFG_EXT   */